package com.mindata.blockchain.block.db;

import javax.annotation.Resource;

import org.iq80.leveldb.DB;
import org.iq80.leveldb.impl.Iq80DBFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * levelDB
 *
 * @author wuweifeng wrote on 2018/4/20.
 */
@Component
@ConditionalOnProperty("db.levelDB")
public class LevelDbStoreImpl implements DbStore {
	@Resource
	private DB db;

	@Override
	public void put(final String key, final String value) {
		db.put(Iq80DBFactory.bytes(key), Iq80DBFactory.bytes(value));
	}

	@Override
	public String get(final String key) {
		return Iq80DBFactory.asString(db.get(Iq80DBFactory.bytes(key)));
	}

	@Override
	public void remove(final String key) {
		db.delete(Iq80DBFactory.bytes(key));
	}
}
